import { fileURLToPath, URL } from 'node:url'
import eslintPlugin from 'vite-plugin-eslint'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import path from "path"
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),

    createSvgIconsPlugin({
      // 指定要读取svg图标的文件夹
      iconDirs: [path.resolve(process.cwd(), 'src/assets/svg')],
      // 指定symbolId格式  读取文件已当前文件名为主
      symbolId: '[name]'
      // 

      //  还需要创建一个组件专门来是读取svg图标
    }),


    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    eslintPlugin({
      include: ['src/**/*.js', 'src/**/*.vue', 'src/*.js', 'src/*.vue']
      // 规定哪些文件 必须符合exlinst 规范   **/ 当前的所有的文件夹  包括子孙文件件   /*.js 所有的js文件
    })
  ],
  server: {
    proxy: {
      '/api': {
        // target: 'http://127.0.0.1:3300/',
        target: 'http://123.249.70.8:7001/',
        // target: 'http://127.0.0.1:3300/',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
    }
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})
